﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace QntPlatform
{
    public interface IStrParse
    {
        string ToText<T>(T obj);
        T Parse<T>(string txt);
    }
    public class StrParse : IStrParse
    {
        public T Parse<T>(string txt)
        {
           return JsonConvert.DeserializeObject<T>(txt);
        }

        public string ToText<T>(T obj)
        {
            return JsonConvert.SerializeObject(obj, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                Error = (p1, p2) => {
                    Log.Default().Error(p2.ErrorContext.OriginalObject + "");
                }
            });
        }
    }
}
